package com.gdut.multiusercommunicationsystem.controller;

import com.gdut.multiusercommunicationsystem.mapper.InviteUserMapper;
import com.gdut.multiusercommunicationsystem.model.User;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class InviteUserController {
    @Resource
    public InviteUserMapper mapper;

    @PostMapping("/sendInvite")
    @ResponseBody
    public void sendInvite(String text, String toUserId, HttpServletRequest request){
        HttpSession httpSession=request.getSession(false);
        User user=(User) httpSession.getAttribute("user");
        int toUser=Integer.parseInt(toUserId);
        mapper.insertInvite(user.getUserId(), toUser,text);
        System.out.println("已插入到请求好友表中");
    }
}
